from sanic import Sanic
from sanic.response import json, html, text
import mysql.connector
# import json

app = Sanic(__name__)

def getDb():

	mydb = mysql.connector.connect(
	  host="localhost",       # 数据库主机地址
	  user="root",    # 数据库用户名
	  passwd="root",   # 数据库密码
	  database="weizandata"
	)

	mycursor = mydb.cursor()
	#sql="SELECT * FROM youjutell;"
	#mycursor.execute(sql)
	mycursor.callproc("gaibiaoqian")
	mydb.commit()
	myresult = mycursor.fetchall()     # fetchall() 获取所有记录
	print(myresult)
	return myresult


@app.route("/api/submitCount", methods=["GET"])
async def index(request):
	return json(getDb())


if __name__ == '__main__':

    app.run(host="0.0.0.0", port=8000)